package com.mrlee.controller;

import com.mrlee.bean.Admin;
import com.mrlee.service.AdminService;
import com.mrlee.utils.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/3/21.
 */
@Controller
public class UserController {

    @Resource
    private AdminService adminService;

    /**
     * 管理员修改信息页
     * @return
     */
    @RequestMapping("userinfo")
    public String userInfo(){
        return "/user/user_info";
    }

    /**
     * 修改管理员信息
     * @param adminId 管理员Id
     * @param name 姓名
     * @param tel 电话
     * @param email 邮箱
     * @return
     */
    @ResponseBody
    @RequestMapping("updateuser")
    public AjaxResult updateUser(@RequestParam("adminId")Integer adminId,
                                 @RequestParam("name")String name,
                                 @RequestParam("tel")String tel,
                                 @RequestParam("email")String email){
        Admin admin = new Admin();
        admin.setAdminId(adminId);
        admin.setName(name);
        admin.setTelephone(tel);
        admin.setEmail(email);
        return adminService.updateAdminInfo(admin);
    }

    @ResponseBody
    @RequestMapping("/usermodi")
    public AjaxResult modi(@RequestParam("npsw")Integer npsw,
                       @RequestParam("psw")Integer psw,
                       @RequestParam("npsw1")Integer npsw1,
                       @RequestParam("npsw2")Integer npsw2){
        AjaxResult ajaxResult = new AjaxResult();
        if (npsw!=psw){
            ajaxResult.setMessage("旧密码不正确");
            return ajaxResult;
        }else if(npsw1==null||npsw2==null){
            ajaxResult.setMessage("请输入新密码");
            return ajaxResult;
        }else if (npsw1!=npsw2){
            ajaxResult.setMessage("两次输入密码不一致");
            return ajaxResult;
        }else {
            ajaxResult.setMessage("修改成功");
            return ajaxResult;
        }
    }

}
